package com.msb.mall.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.msb.common.vo.CommonPageReq;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msb.common.utils.PageUtils;
import com.msb.common.utils.Query;

import com.msb.mall.core.dao.ware.WareInfoDao;
import com.msb.mall.core.entity.ware.WareInfoEntity;
import com.msb.mall.ware.service.WareInfoService;


@Service("wareInfoService")
public class WareInfoServiceImpl extends ServiceImpl<WareInfoDao, WareInfoEntity> implements WareInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WareInfoEntity> page = this.page(
                new Query<WareInfoEntity>().getPage(params),
                new QueryWrapper<WareInfoEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageCondition(CommonPageReq<Map<String, Object>> req) {
        Page<WareInfoEntity> page = new Page<>(req.getCurrPage(), req.getPageSize());

        Map<String, Object> param = req.getData();
        LambdaQueryWrapper<WareInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        if (param != null) {
            String name = (String) param.get("name");
            queryWrapper.like(StringUtils.isNotEmpty(name), WareInfoEntity::getName, name);
        }
        Page<WareInfoEntity> wareInfoEntityPage = baseMapper.selectPage(page, queryWrapper);
        return new PageUtils(wareInfoEntityPage);
    }

}